// pages/article/article.js
//var eventObj = require("../template/template.wxs");
var sayname = require("../../template/template.js");
var menuEvent = require("../../utils/menuEvent.js").menuEvent;
const app = getApp();
Page({
  
  /**
   * 页面的初始数据
   */
  data: {
      hqimage: app.hqimage.webUrl,
      itemList:null,
      pageIndex:1,
      menuarray: '',// [{ message: "横琴定位" }, { message: "横琴交通" }, { message: "横琴规划" }, { message: "横琴经济" }],
      menuitem: {
        showmenu1: true,
        showmenu2: true,
        showmenu3: true,
        showmenu4: true,
        showmenu5: true

      }     
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  //
    var that=this;
   // console.log("请求的地址是：" + app.hqApi );
     wx.request({
       url: app.hqApi.webUrl + '/api/Article/GetArticleMentList?pageIndex=1',
       success: function (datas) {
        
        that.setData({
           itemList:datas.data,
           pageIndex:1
        });
       }
     });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   // console.log("地址：");
    //console.log(app);
    //console.log(this.hqApi.webUrl + '/api/EstateApi/QueryEstateInfo');
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   // console.log(menuEvent);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '正在加载',
    })
  
    //console.log("?");
    var that = this;
    var pageIndex=that.data.pageIndex;
    pageIndex=pageIndex+1;
   
    console.log("当前索引是");
    // console.log("请求的地址是：" + app.hqApi );
    wx.request({
      url: app.hqApi.webUrl + '/api/Article/GetArticleMentList?pageIndex='+pageIndex,
      success: function (datas) {
        //  console.log(datas.data);
        var dataArray = that.data.itemList.concat(datas.data);
        that.setData({
          itemList: dataArray,
          pageIndex:pageIndex
        });
        setTimeout(function(){
          wx.hideLoading()

        },500)

        //console.log("最后的数据是:");
        //console.log(that.data.itemList);
        //console.log("页数是："+pageIndex);
      }
    });   
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  onPageScroll:function(e){
    //console.log(e);
    //console.log(e);
   // console.log("Page Scroll");    
  }
  ,

  templateEvent: function (e) {
    var that = this;
    sayname.GetMemu(that, e.currentTarget.dataset.event);//加载菜单数据
    menuEvent[e.currentTarget.dataset.event](e, that);//绑定二级菜单事件

  },
  getContent:function(e){
    var Id = e.currentTarget.dataset.event;
    wx.navigateTo({
      url:"../ArticleDetails/ArticleDetails?mItemID="+Id
    })
   // console.log(e);
  }
})